﻿<?xml version="1.0" encoding="utf-8"?>
<!-- adfsg -->

<xs:schema id="Configuration"
    targetNamespace="http://OCXS.org/Configuration"
    elementFormDefault="qualified"
    xmlns="http://OCXS.org/Configuration"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
>

  <!-- Elements definition -->
  <!-- Configuration is the root element in the configuration hierarchy -->
  <xs:element name="Configuration" type="ConfigurationType"/>

  <!-- Types definition -->
  <!-- Root -->
  <!-- The configuration root has a first section for variables 
       definition and a second one for variable-group mapping in 
       order to create the node/item hierarchy for OPC variables. -->
  <xs:complexType name="ConfigurationType">
    <xs:sequence>
      <xs:element name="Variables" type="VariablesType"/>
    </xs:sequence>
  </xs:complexType>
  
  <!-- Variables -->
  <xs:complexType name="VariablesType">
    <xs:sequence>
      <xs:element name="Variable" maxOccurs="unbounded" minOccurs="0" type="VariableType"/>
    </xs:sequence>
  </xs:complexType>

  <!-- Variable -->
  <!-- VariableDescription is mapped as an ItemProperty
       VariableType is mapped as an ItemProperty
       VariableMU is mapped as an ItemProperty -->
  <xs:complexType name="VariableType">
    <xs:sequence>
      <xs:element name="VariablePath" type="PathType"/>
      <xs:element name="VariableName" type="IdentifierType"/>
      <xs:element name="VariableDescription" type="xs:string" default="No description provided for this variable."/>
      <xs:element name="VariableT" type="VariableTType"/>
      <xs:element name="VariableMU" type="VariableMUType"/>
      <xs:element name="VariableGenerator" type="VariableGeneratorType"/>
      <xs:element name="VariableValue"/>
    </xs:sequence>
  </xs:complexType>
  
  <!-- Variable type (T) -->
  <xs:simpleType name="VariableTType">
    <xs:restriction base="xs:string">
      <xs:enumeration value="Bit"/>
      <xs:enumeration value="Temperature"/>
      <xs:enumeration value="Pressure"/>
      <xs:enumeration value="Volume"/>
    </xs:restriction>
  </xs:simpleType>
  
  <!-- Variable MU -->
  <xs:simpleType name="VariableMUType">
    <xs:restriction base="xs:string">
      <xs:pattern value="\w*"/>
    </xs:restriction>
  </xs:simpleType>

  <!-- Variable generator type -->
  <xs:complexType name="VariableGeneratorType">
    <xs:sequence>
      <xs:element name="GeneratingFunction" type="GeneratingFunctionType" minOccurs="0" maxOccurs="1"/>
      <xs:element name="StaticValues" minOccurs="0" maxOccurs="1">
        <xs:complexType>
          <xs:sequence>
            <xs:element name="StaticValue" type="VariableModuleValueType" minOccurs="1" maxOccurs="unbounded"/>
          </xs:sequence>
        </xs:complexType>
      </xs:element>
      <xs:element name="PeriodUpdate" type="PeriodUpdateType"/>
    </xs:sequence>
  </xs:complexType>
  
  <!-- Generating function type -->
  <xs:simpleType name="GeneratingFunctionType">
    <xs:restriction base="xs:string">
      <xs:enumeration value="Null"/>
      <xs:enumeration value="Sine"/>
      <xs:enumeration value="Cosine"/>
      <xs:enumeration value="Ramp"/>
      <xs:enumeration value="Linear"/>
      <xs:enumeration value="SquareWave"/>
    </xs:restriction>
  </xs:simpleType>

  <!-- Period (ms) -->
  <xs:simpleType name="PeriodUpdateType">
    <xs:restriction base="xs:int">
      <xs:minInclusive value="1"/>
      <xs:maxInclusive value="200000"/>
    </xs:restriction>
  </xs:simpleType>
  
  <!-- Value for variables -->
  <xs:simpleType name="VariableModuleValueType">
    <xs:restriction base="xs:float">
      
    </xs:restriction>
  </xs:simpleType>

  <!-- Identifiers for elements -->
  <xs:simpleType name="IdentifierType">
    <xs:restriction base="xs:string">
      <xs:pattern value="([a-zA-Z])*([a-zA-Z0-9])*"/>
    </xs:restriction>
  </xs:simpleType>

  <!-- Identifiers for elements -->
  <xs:simpleType name="PathType">
    <xs:restriction base="xs:string">
      <xs:pattern value="([a-zA-Z]\w+\/)+"/>
    </xs:restriction>
  </xs:simpleType>
  
</xs:schema>
